Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for listing sources on customers #1064

Merged
merged 1 commit into from
Nov 29, 2017
Merged

Add support for listing sources on customers #1064

merged 1 commit into from
Nov 29, 2017

Conversation

ob-stripe
Copy link
Contributor

r? @remi-stripe
cc @stripe/api-libraries

Fixes #1062.

This PR adds support for listing sources on customers, with optional filtering by source type.

It should be noted that while source objects are top-level resources, they are not directly listable (they can only be listed when attached to a specific customer). I have named the method List so as to be consistent with StripeCardService / StripeBankAccountService, and I think the presence of customerId in the method's signature makes it clear that this method only applies to customers.

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some comments though I'm approving as you don't have to make any changes.


if (listOptions == null) {
listOptions = new StripeSourceListOptions();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to do this? Is it to ensure that object is passed as source even if nothing is sent? Asking because we don't do this in other List methods such as customer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. The StripeSourceListOptions object will ensure that object=source is added as a query parameter in the request. This seemed less hacky than hardcoding the parameter in the URL, but it does force us to instantiate an object if none is provided.

@@ -40,6 +40,19 @@ public virtual StripeSource Detach(string customerId, string sourceId, StripeReq
);
}

public virtual StripeList<StripeSource> List(string customerId, StripeSourceListOptions listOptions = null, StripeRequestOptions requestOptions = null)
{
var url = string.Format(Urls.CustomerSources, customerId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth using a method to share the code? Not sure but that's what we do in other services (though the URL is used more than twice)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is trivial enough that there's not much value in sharing it.

That said, other API methods on StripeSourceService should definitely use the Urls object like all other API methods rather than hardcoding the URLs. We should fix this separately.

};
var SourceBitcoin = sourceService.Create(SourceBitcoinCreateOptions);

SourceAttachOptions.Source = SourceBitcoin.Id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but I like having separate options instances. Jayme used to compare the type on the object to the info on the options object itself but here since you override you can't do this.

It's definite more verbose my way but I found it cleaner when I started to work on the library. Feel free to ignore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, not sure why I missed this comment earlier.

Yeah, if you need the options object in your test it's better to instantiate it separately. In this case the options object are only instantiated within the test constructor though, and only the resulting list objects are persisted and used in test assertions.

SourceCard.Card.Brand.Should().Be("Visa");

var SourceBitcoin = SourceListAll.Data[1];
SourceBitcoin.Type.Should().Be(StripeSourceType.Bitcoin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't bitcoin be first? Aren't sources returned with most recent first? Or is it due to the default source always being first even if added before and this being undocumented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the card source is attached first and becomes the default source.

It's definitely not great practice to rely on that behavior in a test, and I should probably not have hardcoded the indices, but it's probably not worth putting in too much effort in those tests since we plan to 🔥 them and use stripe-mock Soon™️.

@ob-stripe ob-stripe mentioned this pull request Nov 29, 2017
7 tasks
@ob-stripe ob-stripe merged commit 7bba81d into master Nov 29, 2017
@ob-stripe ob-stripe deleted the ob-fix-1062 branch November 29, 2017 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants